package com.xunk.scene.domain;

import com.xunk.common.core.text.Convert;
import com.xunk.common.core.utils.BeanUtil;
import com.xunk.common.security.utils.SecurityUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @ProjectName: HIM
 * @Package: com.xunk.scene.domain
 * @ClassName: AddScene
 * @Author: luanzhiwei
 * @Description: 添加场景实体类
 * @Date: 2021/5/7 14:32
 * @Version: 1.0
 */
@Data
@EqualsAndHashCode
@ToString
@NoArgsConstructor
public class AddOrUpdateScene extends Scene {

    /**
     * 设备条件
     */
    private List<SceneConditionEquipment> conditionEquipments;
    /**
     * 生效时段条件
     */
    private SceneConditionEffectivePeriod conditionEffectivePeriod;
    /**
     * 天气条件
     */
    private List<SceneConditionWeather> conditionWeathers;
    /**
     * 定时执行
     */
    private List<TaskSchedule> taskSchedules;


    /**
     * 设备动作
     */
    private List<SceneActionEquipment> actionEquipments;
    /**
     * 消息动作
     */
    private SceneActionMsg actionMsg;

    /**
     * 生效时间段不为空时，至少选择一个条件
     *
     * @return
     */
    public boolean isPeriodOk() {
        if (BeanUtil.isNotEmptyBean(this.conditionEffectivePeriod)) {
            if (CollectionUtils.isEmpty(conditionWeathers) && CollectionUtils.isEmpty(conditionEquipments)) {
                return false;
            }
        }
        return true;
    }

    /**
     * 赋值scene
     *
     * @param scene
     */
    public void setScene(Scene scene) {
        this.setId(scene.getId());
        this.setSceneName(scene.getSceneName());
        this.setSceneCode(scene.getSceneCode());
        this.setHomePage(scene.getHomePage());
        this.setProfileUrl(scene.getProfileUrl());
        this.setHomeId(scene.getHomeId());
        this.setDelFlag(scene.getDelFlag());
        this.setActiveFlag(scene.getActiveFlag());
        this.setRelationType(scene.getRelationType());
        this.setExecType(scene.getExecType());
        this.setIsModel(scene.getIsModel());
        this.setDerive(scene.getDerive());
        this.setTags(scene.getTags());
        this.setCreateBy(scene.getCreateBy());
        this.setCreateTime(scene.getCreateTime());
        this.setUpdateBy(scene.getUpdateBy());
        this.setUpdateTime(scene.getUpdateTime());
        this.setRemark(scene.getRemark());
    }

    /**
     * 抽取该实体类继承的scene，操作该返回值，不影响当前对象继承的父类scene
     *
     * @return
     */
    public Scene extractScene() {
        final Scene scene = new Scene();
        scene.setId(this.getId());
        scene.setSceneName(this.getSceneName());
        scene.setSceneCode(this.getSceneCode());
        scene.setHomePage(this.getHomePage());
        scene.setProfileUrl(this.getProfileUrl());
        scene.setHomeId(this.getHomeId());
        scene.setDelFlag(this.getDelFlag());
        scene.setActiveFlag(this.getActiveFlag());
        scene.setRelationType(this.getRelationType());
        scene.setExecType(this.getExecType());
        scene.setIsModel(this.getIsModel());
        scene.setDerive(this.getDerive());
        scene.setTags(this.getTags());
        scene.setCreateBy(this.getCreateBy());
        scene.setCreateTime(this.getCreateTime());
        scene.setUpdateBy(Convert.toStr(SecurityUtils.getUserId()));
        scene.setUpdateTime(this.getUpdateTime());
        scene.setRemark(this.getRemark());
        return scene;
    }
}
